import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // namespace: true,
  state: {
    userName: '',
    token: '',
    count: 0,
  },
  getters: {
    userName: state => state.userName,
    token: state => state.token,
    count: state => state.count,
  },
  mutations: {
    updateUN(state, name) {
      state.userName = name;
    },
    updateToken(state, token) {
      state.token = token;
    },
    addCount(state) {
      state.count++;
    },
    lessCount(state) {
      state.count--;
    },
  },
  actions: {
    updateUN ({ commit }, name) {
      commit('updateUN', name)
    },
    updateToken ({ commit }) {
      commit('updateToken')
    },
    addCount ({ commit }) {
      commit('updateCount')
    },
    lessCount({ commit }) {
      commit('lessCount')
    },
  },
  modules: {
  }
})
